package lec04.pm.gm.v2;

public class Point implements Comparable<Point> {

	@Override
	public String toString() {
		return String.format("(%d, %d)", x, y);
	}

	public void setY(int n) {
		this.y = n;

	}

	public void setX(int n) {
		this.x = n;

	}

	protected int x;
	protected int y;

	public int getX() {
		return x;
	}

	public Point(int x, int y) {
		super();
		this.x = x;
		this.y = y;
	}

	public Point() {
		this(0, 0);
	}

	public int getY() {
		return y;
	}

	@Override
	public int compareTo(Point that) {
		int dx = this.x - that.x;
		if (dx != 0)
			return dx;
		return this.y - that.y;
	}

	public double getDistance(Line line) {
		Point A = this;
		Point B = line.getP();
		Point C = line.getQ();
		double c = A.getDistance(B);
		double b = A.getDistance(C);
		double a = B.getDistance(C);
		double s = (a + b + c) / 2;
		double area= Math.sqrt(s * (s - a) * (s - b) * (s - c));
		return area*2/a;
	}

	private double getDistance(Point that) {
		int dx = this.x - that.x;
		int dy = this.y - that.y;

		return Math.sqrt(dx * dx + dy * dy);
	}

}
